//
//  HOMaintainHistoryViewController.m
//  微度报修
//
//  Created by foguo-mac-1 on 6/12/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HOMaintainHistoryViewController.h"
#import "HOMaintainHistoryCell.h"
#import "HOMaintainHistoryEntity.h"
#import "UIImageView+WebCache.h"
#import "HOUtils.h"

@interface HOMaintainHistoryViewController ()

@end

@implementation HOMaintainHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self initTableView];
	[self initTestData];
}

- (void)initTestData
{
	for(int i = 0; i < 10; i ++)
	{
		HOMaintainHistoryEntity *historyEntity = [[HOMaintainHistoryEntity alloc] init];
		historyEntity.historyId = 1025343;
		historyEntity.recorderName = @"郭伟利";
		historyEntity.department = @"后勤处";
		historyEntity.status = @"未处理";
		historyEntity.headerImgUrl = @"http://img3.3lian.com/2013/s1/59/d/73.jpg";
		historyEntity.content = @"这是内容abcdefghijk33lmnopqrstuvwxyz这是内容abcdefghijklmno33pqrstuvwxyz这是内容abcdefghijklmnopqrstuvwxyz33是内容abcdefghijklmnopqrstuvwxyz";
		[self.tableViewDataList addObject:historyEntity];
	}
}

- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	[self setNavigationItemTitle:@"回复信息列表"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - -- UITableViewDelegate/UITableViewDataResource implement methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UILabel *lbl = [[[UILabel alloc] init] autorelease];
	
	HOMaintainHistoryEntity *historyEntity = [self.tableViewDataList objectAtIndex:indexPath.section];
	lbl.frame = CGRectMake(60, 0, [HOUtils getScreenWidth] - 70, 500);
	lbl.text = historyEntity.content;
	[lbl sizeToFit];
	return 80 + lbl.frame.size.height;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
	NSInteger count = [self.tableViewDataList count];
	[self updateNoResultView:count];;
    return count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return HO_HORIZONAL_PADDING;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *HOMaintainHistoryCellIdentifier = @"HOMaintainHistoryCellIdentifier";
	HOMaintainHistoryCell *cell = (HOMaintainHistoryCell *)[tableView dequeueReusableCellWithIdentifier:HOMaintainHistoryCellIdentifier];
	if(cell == nil)
	{
		cell = [[NSBundle mainBundle] loadNibNamed:@"HOMaintainHistoryCell" owner:self options:nil][0];
	}
	
	HOMaintainHistoryEntity *historyEntity = [self.tableViewDataList objectAtIndex:indexPath.section];
	[cell.headerImgView sd_setImageWithURL:[NSURL URLWithString:historyEntity.headerImgUrl] placeholderImage:nil];
	cell.recorderNameLbl.text = [NSString stringWithFormat:@"%d-%@", historyEntity.historyId, historyEntity.recorderName];
	cell.departmentLbl.text = [NSString stringWithFormat:@"科室:%@    当前状态:%@", historyEntity.department, historyEntity.status];
	cell.assignToLbl.text = [NSString stringWithFormat:@"任务分配给:%@", historyEntity.assignTo];
	cell.contentLbl.frame = CGRectMake(60, cell.contentLbl.frame.origin.y, [HOUtils getScreenWidth] - 70, 500);
	cell.contentLbl.text = historyEntity.content;
	[cell.contentLbl sizeToFit];
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}
#pragma mark - -- tool

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
